﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace GUITree
{
	// Token: 0x020004B8 RID: 1208
	[AddComponentMenu("GUITree/Tree Node", 1000)]
	[RequireComponent(typeof(RectTransform))]
	public class TreeNode : UIBehaviour, ITreeLayoutElement, ILayoutSelfController, ILayoutElement, ILayoutController
	{
		// Token: 0x17000354 RID: 852
		// (get) Token: 0x06001E68 RID: 7784 RVA: 0x000BF7FC File Offset: 0x000BD9FC
		public float minWidth
		{
			get
			{
				return this.preferredWidth;
			}
		}

		// Token: 0x17000355 RID: 853
		// (get) Token: 0x06001E69 RID: 7785 RVA: 0x000BF804 File Offset: 0x000BDA04
		public float preferredWidth
		{
			get
			{
				return this.m_PreferredWidth + (float)this.indent * this.indentSize;
			}
		}

		// Token: 0x17000356 RID: 854
		// (get) Token: 0x06001E6A RID: 7786 RVA: 0x000BF81C File Offset: 0x000BDA1C
		public float flexibleWidth
		{
			get
			{
				return this.preferredWidth;
			}
		}

		// Token: 0x17000357 RID: 855
		// (get) Token: 0x06001E6B RID: 7787 RVA: 0x000BF824 File Offset: 0x000BDA24
		public float minHeight
		{
			get
			{
				return this.preferredHeight;
			}
		}

		// Token: 0x17000358 RID: 856
		// (get) Token: 0x06001E6C RID: 7788 RVA: 0x000BF82C File Offset: 0x000BDA2C
		public float preferredHeight
		{
			get
			{
				return this.m_PreferredHeight;
			}
		}

		// Token: 0x17000359 RID: 857
		// (get) Token: 0x06001E6D RID: 7789 RVA: 0x000BF834 File Offset: 0x000BDA34
		public float flexibleHeight
		{
			get
			{
				return this.preferredHeight;
			}
		}

		// Token: 0x1700035A RID: 858
		// (get) Token: 0x06001E6E RID: 7790 RVA: 0x000BF83C File Offset: 0x000BDA3C
		public int layoutPriority
		{
			get
			{
				return int.MaxValue;
			}
		}

		// Token: 0x1700035B RID: 859
		// (get) Token: 0x06001E6F RID: 7791 RVA: 0x000BF844 File Offset: 0x000BDA44
		public RectTransform rectTransform
		{
			get
			{
				if (this.m_Rect == null)
				{
					this.m_Rect = base.GetComponent<RectTransform>();
				}
				return this.m_Rect;
			}
		}

		// Token: 0x1700035C RID: 860
		// (get) Token: 0x06001E70 RID: 7792 RVA: 0x000BF86C File Offset: 0x000BDA6C
		// (set) Token: 0x06001E71 RID: 7793 RVA: 0x000BF874 File Offset: 0x000BDA74
		public int indent
		{
			get
			{
				return this.m_Indent;
			}
			set
			{
				if (SetPropertyUtility.SetStruct<int>(ref this.m_Indent, value))
				{
					this.SetDirty();
				}
			}
		}

		// Token: 0x1700035D RID: 861
		// (get) Token: 0x06001E72 RID: 7794 RVA: 0x000BF890 File Offset: 0x000BDA90
		// (set) Token: 0x06001E73 RID: 7795 RVA: 0x000BF898 File Offset: 0x000BDA98
		public float indentSize
		{
			get
			{
				return this.m_IndentSize;
			}
			set
			{
				if (SetPropertyUtility.SetStruct<float>(ref this.m_IndentSize, value))
				{
					this.SetDirty();
				}
			}
		}

		// Token: 0x06001E74 RID: 7796 RVA: 0x000BF8B4 File Offset: 0x000BDAB4
		protected override void OnEnable()
		{
			base.OnEnable();
			this.SetDirty();
		}

		// Token: 0x06001E75 RID: 7797 RVA: 0x000BF8C4 File Offset: 0x000BDAC4
		protected override void OnDisable()
		{
			this.m_Tracker.Clear();
			if (this.rectTransform)
			{
				LayoutRebuilder.MarkLayoutForRebuild(this.rectTransform);
			}
			base.OnDisable();
		}

		// Token: 0x06001E76 RID: 7798 RVA: 0x000BF8F4 File Offset: 0x000BDAF4
		public void CalculateLayoutInputHorizontal()
		{
			int childCount = this.rectTransform.childCount;
			float num = 0f;
			for (int i = 0; i < childCount; i++)
			{
				ITreeLayoutElement component = this.rectTransform.GetChild(i).GetComponent<ITreeLayoutElement>();
				if (component != null)
				{
					num += LayoutUtility.GetPreferredSize(component, 0);
				}
			}
			this.m_PreferredWidth = num;
		}

		// Token: 0x06001E77 RID: 7799 RVA: 0x000BF954 File Offset: 0x000BDB54
		public void CalculateLayoutInputVertical()
		{
			int childCount = this.rectTransform.childCount;
			float num = 0f;
			for (int i = 0; i < childCount; i++)
			{
				ITreeLayoutElement component = this.rectTransform.GetChild(i).GetComponent<ITreeLayoutElement>();
				if (component != null)
				{
					float preferredSize = LayoutUtility.GetPreferredSize(component, 1);
					if (num < preferredSize)
					{
						num = preferredSize;
					}
				}
			}
			this.m_PreferredHeight = num;
		}

		// Token: 0x06001E78 RID: 7800 RVA: 0x000BF9C0 File Offset: 0x000BDBC0
		public void SetLayoutHorizontal()
		{
			this.m_Tracker.Clear();
			this.m_Tracker.Add(this, this.rectTransform, DrivenTransformProperties.AnchoredPositionX | DrivenTransformProperties.SizeDeltaX);
			this.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (float)this.indent * this.indentSize, LayoutUtility.GetPreferredSize(this, 0));
		}

		// Token: 0x06001E79 RID: 7801 RVA: 0x000BFA10 File Offset: 0x000BDC10
		public void SetLayoutVertical()
		{
			this.m_Tracker.Add(this, this.rectTransform, DrivenTransformProperties.SizeDeltaY);
			this.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, LayoutUtility.GetPreferredSize(this, 1));
		}

		// Token: 0x06001E7A RID: 7802 RVA: 0x000BFA3C File Offset: 0x000BDC3C
		protected void SetDirty()
		{
			if (!this.IsActive())
			{
				return;
			}
			if (this.rectTransform != null)
			{
				LayoutRebuilder.MarkLayoutForRebuild(this.rectTransform);
			}
		}

		// Token: 0x040020A1 RID: 8353
		private float m_PreferredWidth = -1f;

		// Token: 0x040020A2 RID: 8354
		private float m_PreferredHeight = -1f;

		// Token: 0x040020A3 RID: 8355
		[NonSerialized]
		private RectTransform m_Rect;

		// Token: 0x040020A4 RID: 8356
		private DrivenRectTransformTracker m_Tracker;

		// Token: 0x040020A5 RID: 8357
		[SerializeField]
		private int m_Indent;

		// Token: 0x040020A6 RID: 8358
		[SerializeField]
		private float m_IndentSize = 32f;
	}
}
